module.exports = Behavior({
  properties: {
    label: String,
    image: String,
    placeholder: String,
    placeholderStyle: String,
    placeholderClass: String,
    disabled: Boolean,
    required: Boolean,
    focus: Boolean,
    dense: Boolean,
    helperText: null,
    cursorSpacing: {
      type: Number,
      value: 0,
    },
    confirmType: {
      type: String,
      value: 'done',
    },
    cursor: Number,
    selectionStart: {
      type: Number,
      value: -1,
    },
    selectionEnd: {
      type: Number,
      value: -1,
    },
    adjustPosition: {
      type: Boolean,
      value: true,
    },
    holdKeyboard: Boolean,
  },

  data: {
    inputFocus: false,
  },

  methods: {
    onInput(e) {
      const { value } = e.detail
      this.setData({ value })
      this.triggerEvent('input', e.detail)
    },

    onFocus(e) {
      this.setData({ inputFocus: true })
      this.triggerEvent('focus', e.detail)
    },

    onBlur(e) {
      this.setData({ inputFocus: false })
      this.triggerEvent('blur', e.detail)
    },

    onConfirm(e) {
      this.triggerEvent('confirm', e.detail)
    },

    onTap() {
      if (!this.data.disabled) {
        this.setData({ inputFocus: true })
      }
    },

    _validate() {
      return true
    },
  },
})
